import React, { useEffect, useState } from 'react'
import ReactQuill from 'react-quill'
import 'react-quill/dist/quill.snow.css'
import './index.css'

function CommonEditor({ editorSubmit, storeEditor }) {
  const [editorState, setEditorState] = useState('')
  const handleChange = content => {

    setEditorState(content)
  }

  //触发提交
  useEffect(() => {
    if (editorSubmit) {
      storeEditor({
        content: editorState
      })
    }
  }, [editorSubmit])

  return (
    <>
      <ReactQuill className="h-[100%]" value={editorState} onChange={handleChange}></ReactQuill>
    </>
  )
}

export default CommonEditor
